package com.coincalf.web.agent;

import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.dto.EntrustOrderDTO;
import com.coincalf.dto.ForexDealOrderDTO;
import com.coincalf.dto.ResultDTO;
import com.coincalf.framework.security.UserDetails;
import com.coincalf.service.EntrustOrderService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author qiang
 */
@RestController
@RequestMapping("/agent/order")
@Api(value = "委托订单", description = "委托订单")
public class AgentOrderController {

    @Autowired
    private EntrustOrderService entrustOrderService;

    @GetMapping("entrustType")
    @ApiOperation(value = "持仓方向下拉选择", httpMethod = "GET")
    public Object entrustType() {
        return entrustOrderService.getEntrustType();
    }


    @GetMapping("/orders")
    @ApiOperation(value = "代理商-委托订单列表", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "交易账户", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "持仓方向typeId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "marketId", value = "交易品种ID", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "parentId",value = "上级ID",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "String", paramType = "query")})
    public ResultDTO orders(@ApiIgnore Page<EntrustOrderDTO> page, String userName, Integer orderId, String typeId, Integer marketId, Integer parentId, String createTime,
                            @ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return ResultDTO.successResult(entrustOrderService.selectOrders(page, userDetails.getId(), userName, orderId, typeId, marketId, parentId,createTime));
    }

    @GetMapping("/dealOrders")
    @ApiOperation(value = "代理商-成交记录", httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "交易账户", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "持仓方向typeId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId",value = "上级ID",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "marketId", value = "交易品种ID", dataType = "int", required = true,paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "String", paramType = "query")})
    public ResultDTO dealOrders(@ApiIgnore Page<ForexDealOrderDTO> page, String userName, Integer orderId, String typeId, Integer marketId, Integer parentId, String createTime,
                                @ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return ResultDTO.successResult(entrustOrderService.selectDealOrders(page, userDetails.getId(), userName, orderId, typeId, marketId,parentId, createTime));
    }

    @GetMapping("/dealOrdersTotal")
    @ApiOperation(value = "代理商-成交记录统计",httpMethod = "GET", authorizations = {@Authorization(value = "Authorization")})
    public ResultDTO dealOrderTotal(@ApiIgnore @AuthenticationPrincipal UserDetails userDetails) {
        return entrustOrderService.selectDealOrdersTotal(userDetails.getId());
    }
}